package net.huashitong.threeSeven.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.core.filter.BaseFilter;
import com.sirdc.modules.utils.ObjectUtils;
import net.huashitong.threeSeven.entity.JdFinishDetail;
import net.huashitong.threeSeven.filter.RequestModelFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class JdFinishDetailDao extends StringDao<JdFinishDetail> {

    public JdFinishDetail queryByCodeAndTime(RequestModelFilter filter) {
        GenericQuery query = createQuery("obj");

        if (ObjectUtils.isNotBlank(filter.getIndexCode())) {
            query.append(" and obj.indexCode = :indexCode");
            query.setParam("indexCode", filter.getIndexCode());
        }
        if (ObjectUtils.isNotBlank(filter.getDateTime())) {
            query.append(" and obj.jdTime = :jdTime");
            query.setParam("jdTime", filter.getDateTime());
        }
        query.setOrder("indexCode", BaseFilter.ASC);
        List<JdFinishDetail> list = query.listResult(filter);
        if (list.size() > 0 && list != null) {
            return list.get(0);
        }
        return null;
    }

    public List<JdFinishDetail> queryByCode(RequestModelFilter filter) {
        GenericQuery query = createQuery("obj");

        if (ObjectUtils.isNotBlank(filter.getIndexCode())) {
            query.append(" and obj.indexCode = :indexCode");
            query.setParam("indexCode", filter.getIndexCode());
        }
        query.setOrder("indexCode", BaseFilter.ASC);
        List<JdFinishDetail> list = query.listResult(filter);
        return list;
    }


    public List<JdFinishDetail> queryByTime(RequestModelFilter filter) {
        GenericQuery query = createQuery("obj");

        if (ObjectUtils.isNotBlank(filter.getDateTime())) {
            query.append(" and obj.jdTime = :jdTime");
            query.setParam("jdTime", filter.getDateTime());
        }
        query.setOrder("indexCode", BaseFilter.ASC);
        List<JdFinishDetail> list = query.listResult(filter);

        return list;
    }

}
